<template>
    <div>
        <el-card class="!border-none" shadow="never">
            <div class="mt-4" v-loading="pager.loading">
                <div>
                    <el-table :data="pager.lists" size="large">
                        <el-table-column prop="id" label="ID" min-width="100" align="center"/>
                        <el-table-column prop="name" label="姓名" min-width="100" align="center"/>
                        <el-table-column prop="card_no" label="身份证号" min-width="150" show-overflow-tooltip align="center"/>
                        <el-table-column prop="sex" label="性别" min-width="100" show-overflow-tooltip align="center">
                            <template #default="{ row }">
                                <span v-if="row.sex == 1">男</span>
                                <span v-else>女</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="age" label="年龄" min-width="100" align="center"/>
                        <el-table-column prop="mobile" label="电话" min-width="100" align="center"/>
                        <el-table-column prop="datetime" label="预约时间" min-width="180" align="center"/>
                        <el-table-column prop="status" label="审核状态" min-width="180" align="center">
                            <template #default="{ row }">
                                <el-tag v-if="row.status == 2" type="success">审核通过</el-tag>
                                <el-tag v-if="row.status == 1" type="info">待审核</el-tag>
                                <el-tag v-if="row.status == 3" type="danger">审核失败</el-tag>
                            </template>
                        </el-table-column>
                        <el-table-column prop="disable_txt" label="禁用状态" min-width="180" align="center"/>

                        <el-table-column label="操作" width="160" fixed="right" align="center">
                            <template #default="{ row }">
                                <el-button link type="primary" @click="handleCheck(row)" v-if="row.status == 1">
                                    审核
                                </el-button>
                                <el-button link type="primary" @click="handleDisable(row.id, 0)" v-if="row.disable == 1">
                                    禁用
                                </el-button>
                                <el-button link type="primary" @click="handleDisable(row.id, 1)" v-if="row.disable == 0">
                                    启用
                                </el-button>
                                <el-button link type="danger" @click="handleDelete(row.id)">
                                    删除
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
                <div class="flex justify-end mt-4">
                    <pagination v-model="pager" @change="getLists" />
                </div>
            </div>
        </el-card>
        <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { usePaging } from '@/hooks/usePaging'
import { orderLists, orderDelete, orderDisable } from '@/api/apis'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false)
const { pager, getLists } = usePaging({
    fetchFun: orderLists
})


const handleCheck = async (row: any) => {
    console.log(row)
    showEdit.value = true
    await nextTick()
    editRef.value?.open()
    editRef.value?.setFormData(row)
}
const handleDisable = async (id: number, status: number) => {
    await feedback.confirm('确定要删除？')
    await orderDisable({ id, status })
    getLists()
    
}
const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await orderDelete({ id })
    getLists()
}
getLists()

</script>

<style scoped></style>